Ever wanted to convert some code from C# to Vb.net, I know I do on a daily basis. Why is it that the world writes the code I am looking for in C# (I know the answer to that, but play along with me for a second). I know the web is cluttered with these sites, but here’s my suggestion.
Category Archives: .Net
Handle access denied in ASP.Net using Global.asax
Due to the way ASP.net processes requests to display a page the user is denied access to, this needs to be entered in your Global.asax file.
In the example below, we get the failed status code and if this is equal to 401, then we clear the content and then forward the user to the Access Denied page.
Private Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs) 'if login failed then display user friendly error page If Response.StatusCode = 401Then Response.ClearContent() Server.Transfer("~/AccessDenied.aspx") End If End Sub
This way, the user doesn't get a standard (not user friendly) debug message.
Filed under .Net, ASP.Net, Error handling, VB.Net
VB.Net function to save data
The following function allows saving data and handles any errors gracefully.