| |

VerySource

 Forgot password?
 Register
Search
View: 775|Reply: 8

Use HttpHandler or HttpModule?

[Copy link]

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-18 14:30:01
| Show all posts |Read mode
Not very familiar with HttpHandler and HttpModule. Now I want to implement the following functions:

When a user requests something like: /Info/Detail/*/*/*/*.aspx, such as
/Info/Detail/2016/06/30/1584587.aspx, I first determine whether the file exists, if it does not exist, create it, otherwise visit the page directly. Functions similarly to file system caching.

I now use HttpHandler to handle it and find that the file has been created, but the content of the window to access the page is blank. If you move the created file to another directory, such as / Info /, you can access it. Later I added after the creation of MyHandler's ProcessRequest:
context.Response.Redirect (context.Request.Path);
It doesn't work, it will cause an endless load ~~

What should I do, or should I use HttpModule?

I kindly ask for your thoughts, thank you! !! !!
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-4-26 22:00:01
| Show all posts
Use HttpHandler, or HttpHandlerFactory.
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-4-27 10:45:01
| Show all posts
It is true to use HttpHandler to process certain types of files.
However, if the file /Info/Detail/2016/06/30/1584587.aspx does not exist, IIS directly returns a 404 error to the client, and will not pass the request to aspnet_isapi.dll for processing, nor will it be passed to you to write HttpHandler.
I think your description is a bit strange.
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-27 12:00:01
| Show all posts
Agree withmgcfox

But * .aspx can still go to HttpHandler if it doesn't exist.
If it is something else, it won't work. Because * .aspx is still explained through asp.net.

Others will not work. Iis. Direct report does not exist.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-27 12:45:02
| Show all posts
Use IO to judge. Then use server.transfer () to transfer.
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-30 07:30:02
| Show all posts
Thank you for your reply upstairs, my code is as follows:
public void ProcessRequest (HttpContext context)
{
string strFilePath = context.Server.MapPath (context.Request.Path);

bool blnRebuild = false;
if (! File.Exists (strFilePath))
{
blnRebuild = true;
}

if (blnRebuild)
{
// Extract information ID
long lngInfoID = GetInfoIDByPath (context.Request.Path);
CreateInfoDetailPage (lngInfoID, strMainWebRootPath);
}

if (! File.Exists (strFilePath))
{
context.Response.Redirect ("/ Info / Detail / notfound.aspx");
}
else
{
//context.Response.Redirect(context.Request.Path);
//context.Server.Transfer(context.Request.Path);
context.RewritePath (context.Request.Path);
}
}

Server.Transfer has been tried, not good.
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-30 10:30:01
| Show all posts
No exception is thrown after the request, and a blank window is returned. View the source code of the web page as follows:

<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.0 Transitional // EN">
<HTML> <HEAD>
<META http-equiv = Content-Type content = "text / html; charset = gb2312"> </ HEAD>
<BODY> </ BODY> </ HTML>
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-7-11 21:30:01
| Show all posts
shenmue024
   
But if *.aspx does not exist, you can still go to HttpHandler.
If it is something else, it won't work. Because *.aspx is still explained through asp.net.

Others will not work. iis. Direct report does not exist.

-------------------------------------------

Indeed, it was misled by an article.
This is quite strange.
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-7-11 23:00:01
| Show all posts
You check if the file you generated is correct.
Then look at the implementation in Trace.axd.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list