Showing posts with label ASP.Net. Show all posts
Showing posts with label ASP.Net. Show all posts

Monday, October 1, 2012

Skip RedirectFromLoginPage in ASP.Net

Problem:
You have a web application that has a specific redirect page after user logs into the application. But, in certain circumstances, you want to skip it and redirect the user to another page instead of the default page specified after user usually logs into the application.

Solution:
Thanks to a thread from VelocityReviews, I find the solution.
Instead of using
FormsAuthentication.RedirectFromLoginPage(userName, createPersistantCookie) 
use
FormsAuthentication.SetAuthCookie(userName, createPersistantCookie) 
and
Repsonse.Redirect(url)
methods to redirect the user to the page you want.

Share:

Thursday, July 23, 2009

CustomError mode

Error :

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customerrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>

Solution : The exact error hidden in this error message may vary. To reveal and see the error, changing the customErrors mode is necessary.
In web.config, change to mode to RemoteOnly or Off.
Changing the mode to RemoteOnly will enable the error message to be displayed when the web is viewed on the server.
Meanwhile, changing the mode to Off will enable the error message to be displayed when the web is viewed either on the server of outside.


<customErrors mode="Off" defaultRedirect="ErrorPage.aspx">
<error statusCode="404" redirect="ErrorPage.aspx?errNo=404"/>
</customErrors>
Share:

Adding web reference in Visual Studio 2008 or later

Some people get confused adding web reference in Visual Studio 2008 or later, since it's not by default in the Solution explorer. Only Service reference is shown.

Web reference is actually still available on Visual Studio 2008 or later.
Just right-click on the project where the web reference is to be added, choose Add Service Reference, then click Advanced button. Click Add Web Reference beneath, then insert the URL address of the web service, Go. If the URL address is correct, it will be shown in the listbox saying "Web services found at this URL". Insert the reference name, then click Add Reference, OK.

That's all folks ^^
Share:

Wednesday, June 17, 2009

Creating Simplified Duwamish from a scratch

This is a step by step on how to create an asp.net C# web application using simplified Duwamish framework. I call it simplified Duwamish framework, because it is not the real Duwamish. It is my own version. I like it better, after eliminating some parts of the Duwamish framework I rarely use.
FYI, sample for the Duwamish template is already provided when installing Visual Studio .Net 2003.
This is a picture which describes the plot of Duwamish framework.




Picture Source : http://madgeek.com/Articles/SOA/EN/SOA-Softly.html

For more information about Duwamish, refer to http://msdn.microsoft.com/en-us/library/aa288561(VS.71).aspx

For my Simplified Duwamish framework, I only use these projects:
- BusinessFacade (Class Library)
- DataAccess (Class Library)
- Common (Class Library)
- Control (Class Library) -> this project is not in Duwamish framework
- Web Application (ASP.NET Web Application)

1. Create a blank solution
Menu File -> New Project -> Visual C# -> Other Project Types -> Visual Studio Solutions -> Blank Solution, name the solution, and it will appear on the right side of the Solution Explorer.

2. Some things which should be known:
- Common -> does not depend on any other projects
- Control -> depends on Common
- DataAccess -> depends on Common
- BusinessFacade -> depends on Common and DataAccess
- Web Application -> depends on BusinessFacade, Common, and Control
Therefore, this would be the order used in creating projects in the solution.
To create a new project, right-click on the solution, choose Visual C#, then choose the project type.

3. Create Common Project
Add a new project of type Class Library, then name it Common. A class named Class1.cs will be automatically created. It can be renamed later.

4. Create Control Project
Add a new project of type Class Library, then name it Control. A class named Class1.cs will be automatically created. It can be renamed later.

5. Create DataAccess Project
Add a new project of type Class Library, then name it DataAccess. A class named Class1.cs will be automatically created. It can be renamed later.

6. Create BusinessFacade Project
Add a new project of type Class Library, then name it DataAccess. A class named Class1.cs will be automatically created. It can be renamed later.

7. Create Web Application Project
Add a new project of type ASP.Net Web Application, then name the web. A page named Default.aspx will be automatically created. This is usually set as the default page of the web.

8. Manage Project Dependencies
Manage project dependencies as explained in step 2. Right-click on the solution, then choose Project Dependencies.
- Common does not depend on any other projects, so we just skip this.
- Choose Control -> Check Common, since Control depends on Common.
- Choose DataAccess -> Check Common.
- Choose BusinessFacade -> Check DataAccess and Common.
- Choose Web Application -> Check BusinessFacace, Common, and Control.
Then, OK.

9. Adding Project References to the projects
To add references to the project, right-click on the project, choose tab Projects, then choose the project to be referenced.
- Control -> Add reference to Common.
- DataAccess -> Add reference to Common.
- BusinessFacade -> Add references to DataAccess and Common.
- Web Application -> Add references to BusinessFacade, Common, and Control.

10. Setting start-up project and start-up page
Right-click on the Web Application project, then Set as StartUp Project.
Right-click on the index page, then Set as Start Page (Default.aspx is usually set as start page).

11. Rebuild the Solution by right-clicking on the solution, then rebuild.

12. Running in debug mode may be necessary for the first time, after creating the application. Just press F5 to debug.

13. That’s all folks.
Share:

Saturday, June 13, 2009

Appending ArrayList to another ArrayList

A friend of mine asked about how to append an ArrayList to another ArrayList in C#. I found out that it's an easy task as long as the type of the ArrayList is the same. Just have to typecast it to ICollection.
e.g.

ArrayList a = new ArrayList();
a.Add("Array 1");
a.Add("Array 2");

ArrayList b = new ArrayList();
b.Add("Array 3");
b.Add("Array 4");

a.AddRange((ICollection)b);
Share:

You may be intersted in

Related Posts

Updating Table Containing Xml Column via LinkedServer

If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...

About Me

My photo
Is an ordinary man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing.

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts

Blogroll

Followers

Leave a Message