Trying to find a way to parameterize a report name to change in a compiled app

polaro 96 Reputation points
2021-11-29T19:48:30.517+00:00

Greetings,

I have an app that renders SSRS reports for the internet users, secured by Azure authentication tokens. The asp.net page has the report names hardcoded in its .cs file, not accessible after compiling the app.

I have been searching for ways to define a variable somewhere in a view that is editable from IIS, (_ViewStart), for instance, assign a value to it and use it in the .aspx page on runtime

Something like:

The variable in _ViewStart view:

@{

    public static string report = "reportname";

}

must be available in the .cs file below (in bold):

ssrs_report.aspx
ssrs_report.aspx.cs

Any ideas are appreciated. I'd like to avoid recompiling the app every time developers want to point it to a different report

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,292 questions
0 comments No comments
{count} votes

Accepted answer
  1. polaro 96 Reputation points
    2021-12-01T14:31:51.71+00:00

    Greetings,

    I have managed to solve it by utilizing the hiddenfield control.

    In every .aspx file, add the line, specifying the HiddenFieldID (a string) and report path in "Value":

    <asp:HiddenField ID="reportid" Value="/Reports/reportname" runat="server"></asp:HiddenField>
    

    In respective aspx.cs file, reference the hidden field's value as:

    string reportname = Convert.ToString(reportid.Value)
    

    Now, after compiling the app and deploying it to IIS, I can change the Value without recompiling

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,071 Reputation points
    2021-11-30T02:43:40.8+00:00

    Hi @polaro ,
    As far as I think,instead of creating variables, you're better off injecting a service that will generate the values you need as required.For example:

    public interface ILocalisationService  
    {  
        string CurrencySymbol { get; }  
    }  
      
    public class LocalisationService : ILocalisationService  
    {  
        private IConfigurationService _configurationService;  
        private string _currencySymbol;  
      
        public LocalisationService(IConfigurationService configurationService)  
        {  
            _configurationService = configurationService;  
        }  
      
        public string CurrencySymbol => string.IsNullOrEmpty(_currencySymbol)  
            ? _currencySymbol = _configurationService.GetValue("£")  
            : _currencySymbol;  
    }  
    

    Now inject the new service:

    @inject ILocalisationService LocalisationService  
    

    And use it in your view:

    The currency symbol is @LocalisationService.CurrencySymbol  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.