Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:10:34+00:00 2026-05-26T18:10:34+00:00

I have strings like: http://127.0.0.1:22/Test Is there some single function maybe using regular expressions

  • 0

I have strings like:

http://127.0.0.1:22/Test

Is there some single function maybe using regular expressions that I can use to make remove the colon and port number.

It was previously suggested that I use the following but this is giving me problems if the CurrentUrl is null!

var ip = new Uri((string)Session["CurrentUrl"]);
var ipNoPort = string.Format("{0}://{1}/{2}", ip.Scheme, ip.Host, ip.PathAndQuery);
return Session["CurrentUrl"] == null ? Home() : Redirect((string)ipNoPort);

What I really need is some method that combines the three lines and checks for null also.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:10:35+00:00Added an answer on May 26, 2026 at 6:10 pm

    Just test for nullity before using the session variable:

    if(Session["CurrentUrl"] != null)
    {
      var ip = new Uri(Session["CurrentUrl"]);
      var ipNoPort = string.Format("{0}://{1}/{2}", ip.Scheme, ip.Host, ip.PathAndQuery);
      return Redirect(ipNoPort);
    }
    
    return Home();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed that some sites (including the old http://careers.stackoverflow.com 1.0) have query strings that
I have strings like this: http://localhost:2055/web-site-2009/paginas/noticias/**IGP-M recua 0,36% em agosto, aponta FGV**-46.aspx I'd like
I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have strings like 84, 03 etc. that I want to convert to Date
http://www.example.com/http://www.test.com I have tried many different methods using .htaccess with no luck. I need
Say I have strings like these: bunch of other html<a href=http://domain.com/133742/The_Token_I_Want.zip more html and
I have in my db strings like www.domain.com and http://www.domain.com . I want to
Let's say I have a PHP Model-View-Controller framework that maps an address like http://example.com/admin/posts/edit/5
I have this page http://127.0.0.1:8000/user/tom-brandy/ . There is a link on the page to
I have 3 strings, i would like find matches http://www.vkeong.com/2011/food-drink/heng-bak-kut-teh-delights-taman-kepong/#comments http://www.vkeong.com/2009/food-drink/sen-kee-duck-satay-taman-desa-jaya-kepong/ http://www.vkeong.com/2008/food-drink/nasi-lemak-wai-sik-kai-kepong-baru/ for each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.