You are being too modest. You have shown some skill in developing Razor code here so far. Why not have a go yourself, then come back here when you encounter errors that you can't fix?
protected void CapSubmit_Click1(object sender, EventArgs e)
{
if (Page.IsValid == true)
{
Response.Redirect("~/<--The Page with your link for your download-->.aspx");
}
else
{
Label1.Text = "That was incorrect. Please try again.";
}
}
Hope this helps.
Doers get what they want! Everyone else gets what they get.
Also make sure you put the recaptcha control and submit button inside and asp panel and set the defaultbutton="SubmitButton" if you don't you get a crazy enter key behavior.
Doers get what they want! Everyone else gets what they get.
dow7
Member
732 Points
449 Posts
how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 11:23 AM|LINK
Hi,
how to protect a download link for an excel file with recaptcha or something else?
qwe123kids
All-Star
48619 Points
7957 Posts
MVP
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 12:59 PM|LINK
Hi,
Use Authrozation on Folder
OR
Use HttpHanlder or Module for Protection.
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
dow7
Member
732 Points
449 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 01:27 PM|LINK
I mean i want to make the download link available after typing correctly recaptcha words.
pranavkm
Participant
796 Points
106 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 01:30 PM|LINK
Drop it under App_Data. Use Response.WriteFile from a cshtml file to serve the file if the user successfully responds to a ReCaptha challenge.
dow7
Member
732 Points
449 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 01:42 PM|LINK
Can u help me with the code please! I'm a beginer in asp.net razor syntax.
Thank you.
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 02, 2011 05:38 PM|LINK
You are being too modest. You have shown some skill in developing Razor code here so far. Why not have a go yourself, then come back here when you encounter errors that you can't fix?
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
remojr76
Participant
902 Points
303 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 05, 2011 02:12 AM|LINK
You could try this:
Using the "Recaptcha", first register and get your private and public keys from http://www.google.com/recaptcha.
Make an aspx page that has the recaptcha control and a "submit" button.
<%@ Page Title="" MaintainScrollPositionOnPostback="true" Language="C#" MasterPageFile="~/JnCap.Master" AutoEventWireup="true" CodeBehind="Captcha.aspx.cs" Inherits="TheCouponBot.com.Captcha" %> <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %> <asp:Content ID="Content1" ContentPlaceHolderID="CpMain" runat="server"> <table align="center" cellpadding="0" cellspacing="0" style="width: 800px; height: 568px; margin-bottom: 0px"> <tr> <td align="center" class="style5"> <img alt="SpamProtection" src="Images/SpamProtection.jpeg" style="width: 350px; height: 200px" /></td> </tr> <tr> <td align="center" class="style2" style="height: 173px"> <recaptcha:RecaptchaControl ID="recap" PublicKey="<--Your Public Key-->" PrivateKey="<--Your Private Key-->" runat="server" Theme="blackglass" CustomThemeWidget="recaptcha_widget" /> </td> </tr> <tr> <td align="center" class="style2"> <asp:Button ID="CapSubmit" runat="server" Text="Submit" onclick="CapSubmit_Click1" /> </td> </tr> <tr> <td align="center"> <asp:Label ID="Label1" runat="server"></asp:Label> <br /> </td> </tr> </table> </asp:Content>protected void CapSubmit_Click1(object sender, EventArgs e) { if (Page.IsValid == true) { Response.Redirect("~/<--The Page with your link for your download-->.aspx"); } else { Label1.Text = "That was incorrect. Please try again."; } }remojr76
Participant
902 Points
303 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 05, 2011 02:53 AM|LINK
Also make sure you put the recaptcha control and submit button inside and asp panel and set the defaultbutton="SubmitButton" if you don't you get a crazy enter key behavior.
dow7
Member
732 Points
449 Posts
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 05, 2011 08:27 AM|LINK
Well, thank you but this is an asp code example, i'm looking for razor cshtml code. Can u format it for cshtml razor syntax?
Mikesdotnett...
All-Star
154901 Points
19864 Posts
Moderator
MVP
Re: how to protect a download link for an excel file with recaptcha or something else?
Jul 07, 2011 04:57 AM|LINK
@{ if (ReCaptcha.Validate("PRIVATE_KEY")) { var folder = "App_Data"; var path = Path.Combine(Server.MapPath("~/"), folder); var fileName = Request["fileName"]; var AllowedExtensions = new[]{".xls",".xlsx"}; if(!fileName.IsEmpty() && AllowedExtensions.Contains(Path.GetExtension(fileName))){ var file = Path.Combine(path, fileName); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + fileName); Response.TransmitFile(file); } } }Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter