webForumDet fria alternativet

Hämta CustomError url från web.config

.NET

1 svar · 372 visningar · startad av doggelito

Medlem sedan juni 20003 076 inlägg
Frågan#1

Hej,
Jag har denna i web.config:

<customErrors mode="On">
      <error statusCode="403" redirect="/error/http403"/>
      <error statusCode="404" redirect="/error/http404"/>
      <error statusCode="500" redirect="/error/general"/>
</customErrors>

Nu skulle jag vilja kunna hämta upp error 500:s url i en sträng.
Nån som har en susning om hur jag kan göra det?
Typ:

string url = Configuration.CustomErrors.GetError("500").Url;
Medlem sedan juni 20003 076 inlägg
#2

Hitta på:t :)

System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
CustomErrorsSection customErrorsSection = (CustomErrorsSection)configuration.GetSection("system.web/customErrors");
CustomErrorCollection customErrorsCollection = customErrorsSection.Errors;

string url = customErrorsCollection["500"].Redirect;
419 ms totalt · 4 externa anrop · v20260731065814-full.86ec41c2
117 ms — deklarationer (db)
0 ms — hämta statistik (cache)
298 ms — hämta tråd, inlägg och bilagor (db)
118 ms — ändringar (db)