ASP.NET FAQ

  1. Where can I find sample code?

    Check out GotDotNet for some QuickStart tutorials. Another useful reference is IBuySpy where they have a fully-documented sample store web site.

  2. Why does Internet Explorer ask to download a file when I try to view my aspx page?

    This is because IIS does not recognize aspx pages yet. To fix this:
    1. Right click on My Computer and select Manage.
    2. Right click on Default Web Site and select properties.
      Services and Applications -> Internet Information Services -> Default Web Site
    3. Click on the Home Directory Tab
    4. Click the Configuration button.
    5. Click on Add.
    6. Browse and find the file called xspisapi.dll. It should be at C:\WINNT\Microsoft .NET\Framework\v1.0.2204\xspisapi.dll . Make sure you are looking for dll files and not exe files or you won't find it.
    7. Type aspx in the extension field and click Ok
    8. Ok everything and you should be all set! Happy coding.

  3. How do I create my first project?

    Under new projects, Visual C# Projects, select Web Application and type: http://localhost/my-project-name where my-project-name is whatever name you want.

    To view your page, you need to Build it first.
    You can find your page at http://localhost/my-project-name/page-name.aspx in IE.

  4. How do I create index.html in my root folder using Visual Studio?

    If you followed the instructions above, you project will be in a folder under the root directory but won't the root directory itself. So in short you can't really do it in Visual Studio. However, you can easily make an index.html in notepad or any other text editor and create a link to a index page in your project directory.

  5. Why aren't my files in my project? Did I lose them?

    If you created a file outside of Visual Studio, you will need to add the file to your project in VS so that it can be built and used (applies only to aspx & C# files). To see all the files in your project directory, just click on the Show All Files button in your Solution Explorer. If the file is grayed out then it is not included in the project. To include the files, right click on them and select Include in Project. Remember to build to see it work!

  6. How do I add new files to my project?

    Right click on your project name in Solution Explorer and then select Add. Generally you will want to create a new Web Form (.aspx) and remember to name it something.

  7. Do all my files have to have .aspx extensions?

    If your file has asp tags then your pages will need to have a .aspx extension.

  8. Where is my error log?

    You can find your log file here: c:\winnt\system\logfiles\w3svc\date.txt
    However this file only logs who has visited your site and not errors generated on your page. You can ignore this part for your problem set if you are working in .NET.

  9. How do I get the current date and time?

    .NET has a DateTime object. To see how it is used, check out the .NET reference documentation that can be found from your start menu.

  10. How do I pass form data between pages?
    There are quite a number of ways to do this and depending on the task at hand, you would probably want to use a different method. If you are thinking of passing form data to another page for Ex 3 it's actually not necessary, you can place it all in one page.
    1. QueryString - Put it in the URL

      In the button onclick event, you can Response.Redirect to another page placing the variables in the URL.

      e.g.
      String strURL = String.Concat("results.aspx?name=", txtName.Text, "&age=", txtAge.Text);
      Response.Redirect(strURL);

      Then on your results.aspx page you can call Request.Params["name"] to get the name and Request.Params["age"] to get the parameters.


    2. Session - Save it a for awhile

      In the button onclick event, you can save all your variables into the Session and then call Response.Redirect to another page that extracts the values from the Session again.

      e.g.
      Session["name"] = txtName.Text;
      Session["age"] = txtAge.Text;
      Response.Redirect("results.aspx");

      Then on your results.aspx page you can create variables to retreive the value of the Session variables like:
      String strName = Session["name"].ToString();
      String strAge = Session["age"].ToString();


    3. Server.Execute - Fake a page change

      You can see an example of this at testform.aspx.
      The second page testresult.aspx then calls Request.Params["txtName"] to recover the value.

  11. How do I screen scrape?

    For Ex 4 you will need to rip stuff off some other pages.

    HttpWebRequest hwr = (HttpWebRequest) WebRequestFactory.Create(strUrl);
    StreamReader strm = new StreamReader(hwr.GetResponse().GetResponseStream());

    You can then parse the stream using a Regular Expression.

 

Copyright Eugene Chiu, Edmund Chou, Tien-Lok Lau, Yi-Fung Lin, Peter Weng, Norimasa Yoshida, April 2001