c# - How to force a HTTP error in ASP.NET? -
c# - How to force a HTTP error in ASP.NET? -
ide: visual studio 2013 ultimate language: c# asp.net webpage (aspx) problem: hi! have assignment school , making website using asp.net (c#) , need have 3 custom errors added. know how forcefulness 404 error (page not found) , 500 error (error in code behind of page) need 3rd 1 , don't know ones can force.
in navigation menu have href "404page.aspx" 1 doesn't exist in solution 404 error. in menu have href "500error.aspx" , there have wrong code in code behind ("500error.aspx.cs") 500 error.
web.config file:
<customerrors mode="on" defaultredirect="error.aspx"> <error statuscode="404" redirect="error.aspx?error=404"/> <error statuscode="500" redirect="error.aspx?error=500"/> <error statuscode="x" redirect="error.aspx?error=x"/> </customerrors>
error.aspx.cs (code behind error.aspx) file:
protected void page_load(object sender, eventargs e) { labelresult.text = ""; string errorcode = request.querystring.get("error"); if (errorcode.tostring().equals("404")) { labelresult.text = "page contains 404 error."; } if (foutcode.tostring().equals("500")) { labelresult.text = "page contains 500 error."; } }
so need 3rd http error can forcefulness using c# or asp.net.
you either need access page not have permission see or manually throw own error in code behind:
throw new httpexception(403, "access denied");
c# asp.net http
Comments
Post a Comment